package 运行不了的代码;

import java.util.ArrayList;
public class ArrayListAge {
    public static void main(String[] args) {
        final ArrayList<Integer> arr = new ArrayList<>();
        arr.add(10);
        arr.add(16);
        arr.add(47);
        arr.add(24);
        arr.add(64);
        //第三个位置插入90
        arr.add(3, 90);
        System.out.println(arr);
        //获取第2个数
        System.out.println("arr.get(2) = " + arr.get(2));
        System.out.println("arr.size() = " + arr.size());
        //删除1个数
        arr.remove(1);
        System.out.println("arr = " + arr);
        arr.remove("90");
        //修改第4为66
        arr.set(4, 66);
        for (int i = 0; i < arr.size(); i++) {
            System.out.print(arr.get(i) + "\t");
        }
        System.out.println("\n删除年龄大于18");
        for (int i = 0; i < arr.size(); i++) {
            if (arr.get(i) > 18) {
                arr.remove(i);
                i--;
            }

        }
        System.out.println("arr = " + arr);
    }
}

